package service.impl;

import java.util.HashMap;
import java.util.Map;

import service.CartManager;

public enum CartManagerFactory implements CartManager {
	INSTANCE;
	
	private Map<String, Map<String, Integer>> cart = new HashMap<>();
	
	@Override
	public Map<String, Map<String, Integer>> getCart() {
		return cart;
	}

	@Override
	public boolean addToCart(String userId, String bookId) {
		if (cart.containsKey(userId)) {
			Map<String, Integer> userCart = cart.get(userId);
			if (userCart.containsKey(bookId)) {
				int bookCount = userCart.get(bookId);
				userCart.put(bookId, bookCount + 1);
			} else {
				userCart.put(bookId, 1);
			}
		} else {
			Map<String, Integer> userCart = new HashMap<>();
			userCart.put(bookId, 1);
			cart.put(userId, userCart);
		}
		return false;
	}

}
